package com.example.suanfademo;

public class HuiwenString {
    /*
    回文字符串：从左往右读，和从右往左读结果一样
    中心扩散法：枚举所以字符为回文字符串中心



     */
    public String huiwen(String a){
        String string = "";
        char[] charArray = a.toCharArray();
        for(int i=0;i<charArray.length-1;i++){
            String panduan = panduan(a, charArray, i, i);
            String panduan2 = panduan(a,charArray,i,i+1);
            string=string.length()>panduan.length()? string:panduan;
            string= string.length()>panduan2.length()?string:panduan2;
        }

        return string;
    }

    public String panduan(String s,char[] nums,int left,int right){
        while(left>=0 && right<nums.length && nums[left]==nums[right]){
            left--;
            right++;
        }

        return s.substring(left+1,right);
    }

    public static void main(String[] args) {
        HuiwenString hui = new HuiwenString();
        String aacccaaed = hui.huiwen("aacccaaed");
        System.out.println(aacccaaed);
    }

    /**
     *
     */
}
